<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['createBy']" placeholder="请输入创建人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="注册时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择注册时间" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['updateBy']" placeholder="请输入更新人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['corpname']" placeholder="请输入公司名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="注册地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['registerAddress']" placeholder="请输入注册地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="办公地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['officeAddress']" placeholder="请输入办公地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['nsrsbh']" placeholder="请输入纳税人识别号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="税号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sh']" placeholder="请输入税号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['khh']" placeholder="请输入开户行"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="对公账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dgzh']" placeholder="请输入对公账号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="联系人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrxm']" placeholder="请输入联系人姓名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="lxrsj" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrsj']" placeholder="请输入lxrsj"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yx']" placeholder="请输入邮箱"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="营业执照图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yyzztp']" placeholder="请输入营业执照图片"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['htbh']" placeholder="请输入合同编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同签署时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择合同签署时间" v-decorator="['htqssj']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['htfj']" placeholder="请输入合同附件"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['htdz']" placeholder="请输入合同地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="认证状态: 0被驳回, 1待审核, 2审核通过待签署, 3已签署,4已冻结" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['status']" placeholder="请输入认证状态: 0被驳回, 1待审核, 2审核通过待签署, 3已签署,4已冻结"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="md5密码盐" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['salt']" placeholder="请输入md5密码盐"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="登录用户名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['username']" placeholder="请输入登录用户名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="验证码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['smscode']" placeholder="请输入验证码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="法定代表人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fddbr']" placeholder="请输入法定代表人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrxm']" placeholder="请输入被委托人姓名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrsfzh']" placeholder="请输入被委托人身份证号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人职位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrzw']" placeholder="请输入被委托人职位"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人手机号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrsjh']" placeholder="请输入被委托人手机号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人身份证正面照" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrsfzzmz']" placeholder="请输入被委托人身份证正面照"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="被委托人身份证反面照 " :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bwtrsfzfmz']" placeholder="请输入被委托人身份证反面照 "></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="平台综合服务费费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['ptzhfwfl']" placeholder="请输入平台综合服务费费率" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="记账子单元编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dmanbr']" placeholder="请输入记账子单元编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="enterpriseptId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['enterpriseptId']" placeholder="请输入enterpriseptId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="presonalId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['presonalId']" placeholder="请输入presonalId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="contractNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractNo']" placeholder="请输入contractNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="procedureNo" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['procedureNo']" placeholder="请输入procedureNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="charterptId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['charterptId']" placeholder="请输入charterptId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="enterpriseId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['enterpriseId']" placeholder="请输入enterpriseId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="presonalptId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['presonalptId']" placeholder="请输入presonalptId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="charterId" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['charterId']" placeholder="请输入charterId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="子账号名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dmanam']" placeholder="请输入子账号名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="数据来源1PC端注册,2小程序" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sjly']" placeholder="请输入数据来源1PC端注册,2小程序"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="法人身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['frsfzh']" placeholder="请输入法人身份证号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="开户凭证" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['khpz']" placeholder="请输入开户凭证"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="地点经度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['longitude']" placeholder="请输入地点经度" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="地点纬度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['latitude']" placeholder="请输入地点纬度" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="企业类型(1驿站,2人力资源,3企业)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['qylx']" placeholder="请输入企业类型(1驿站,2人力资源,3企业)"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="logo图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['logo']" placeholder="请输入logo图片"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="场所图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['csImg']" placeholder="请输入场所图片"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="企业简介" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['qyjj']" placeholder="请输入企业简介"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="驳回理由" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['reason']" placeholder="请输入驳回理由"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邀请二维码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['inviteQrCode']" placeholder="请输入邀请二维码"></a-input>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'  

  export default {
    name: 'YzCorpinfoForm',
    components: {
      JFormContainer,
      JDate,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/yzcorpinfo/yzCorpinfo/add",
          edit: "/yzcorpinfo/yzCorpinfo/edit",
          queryById: "/yzcorpinfo/yzCorpinfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','corpname','registerAddress','officeAddress','nsrsbh','sh','khh','dgzh','lxrxm','lxrsj','yx','yyzztp','htbh','htqssj','htfj','htdz','status','salt','username','smscode','fddbr','bwtrxm','bwtrsfzh','bwtrzw','bwtrsjh','bwtrsfzzmz','bwtrsfzfmz','ptzhfwfl','dmanbr','enterpriseptId','presonalId','contractNo','procedureNo','charterptId','enterpriseId','presonalptId','charterId','dmanam','sjly','frsfzh','khpz','longitude','latitude','qylx','logo','csImg','qyjj','reason','inviteQrCode'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','corpname','registerAddress','officeAddress','nsrsbh','sh','khh','dgzh','lxrxm','lxrsj','yx','yyzztp','htbh','htqssj','htfj','htdz','status','salt','username','smscode','fddbr','bwtrxm','bwtrsfzh','bwtrzw','bwtrsjh','bwtrsfzzmz','bwtrsfzfmz','ptzhfwfl','dmanbr','enterpriseptId','presonalId','contractNo','procedureNo','charterptId','enterpriseId','presonalptId','charterId','dmanam','sjly','frsfzh','khpz','longitude','latitude','qylx','logo','csImg','qyjj','reason','inviteQrCode'))
      },
    }
  }
</script>